/*自定义TabBar效果
对于自定义标题栏使用有一定的限制
样式：
    标题一     |      标题二
    -----            -----
*/
import 'dart:ffi';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:frametrim/utility/TextUtils.dart';
import 'package:frametrim/utility/screen.dart';
import 'package:frametrim/utility/sq_color.dart';
import 'package:frametrim/views/checkbox_circle.dart';

class MyDriverTabBarView extends StatefulWidget {
  late String mTitle1;
  late String mTitle2;
  late Color? unChooseColor;
  late Color? ChooseColor;
  late double? mFontSize;

  //中间分割线宽高色值
  late double? lineHeight;
  late double? lineWidth;
  late Color? lineColor;

  //tab宽高储存
  late double? mTabHeight;
  late Function(int) onChooseListener;


  MyDriverTabBarView({required this.mTitle1,
    required this.mTitle2,
    this.unChooseColor = const Color(0xff333333),
    this.ChooseColor = const Color(0xff237BFC),
    this.lineColor = const Color(0xffC4C4C4),
    this.lineHeight = 18,
    this.lineWidth = 2,
    this.mTabHeight = 50,
    this.mFontSize = 16,
    required this.onChooseListener});

  @override
  State<StatefulWidget> createState() => MyTabBarViewState();
}

class MyTabBarViewState extends State<MyDriverTabBarView> {
  late int currentIndex;

  @override
  void initState() {
    super.initState();
    currentIndex = 0;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width:Screen.width,
      height: 50,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Stack(
            alignment: Alignment.center,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Container(
                    padding: EdgeInsets.symmetric(horizontal: 20),
                    child: buildTab(0),
                  ),
                  Container(
                    width: widget.lineWidth,
                    height: widget.lineHeight,
                    decoration: ShapeDecoration(
                        color: widget.lineColor,
                        shape: RoundedRectangleBorder(
                            borderRadius:
                            BorderRadius.all(Radius.circular(3)))),
                  ),
                  Container(
                    padding: EdgeInsets.symmetric(horizontal: 20),
                    child: buildTab(1),
                  ),
                ],
              ),
            ],
          )

          // Divider(height: 2,color: Color(0xffEAEAEA),),
        ],
      ),
    );
  }

  Widget buildTab(int mIndex) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () {
        // if(widget.currentIndex!=mIndex){
        setState(() {
          currentIndex = mIndex;
        });

        widget.onChooseListener(mIndex);
        // print('widget.currentIndex=='+widget.currentIndex.toString());
        print('widget.currentIndex==' + currentIndex.toString());
        print('mIndex==' + mIndex.toString());
        // }
        // mListener(index);
      },
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Text(
            mIndex == 0 ? widget.mTitle1 : widget.mTitle2,
            style: TextStyle(
                fontSize: widget.mFontSize,
                color: currentIndex == mIndex
                    ? widget.ChooseColor
                    : widget.unChooseColor),
          ),
          SizedBox(
            height: 6,
          ),
          Container(
            width: 50,
            height: 2,
            decoration: ShapeDecoration(
                color: currentIndex == mIndex
                    ? widget.ChooseColor
                    : Color(0x00000000),
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(Radius.circular(3)))),
          )
        ],
      ),
    );
  }
}
